package com.lo23.data.serializable;


import java.awt.*;

import javax.swing.ImageIcon;


import com.lo23.data.objpicture.Picture;

//import java.awt.image.BufferedImage;

//import java.awt.Graphics;





/*
 * Serializable class of Picture
 * 
 * 
 */

public class PictureThumbnail {

	
	private static final long serialVersionUID = 11L;
	public String pID;
	public double mark;
	public String title;
	public ImageIcon picture;
	public String owner;

	

	public PictureThumbnail(Picture pic, String uid, int maxWidth,  int maxHeight){

		owner = uid;
		pID = pic.getpID();
		mark = pic.getCalcMark();
		title = pic.getTitle();

		double width = 0;
		double height = 0;
		double scale = 0;
		Image img = pic.getPicture().getImage();  
	
		if(img.getWidth(null)>img.getHeight(null)){
			width = maxWidth;
			scale = 1.0*maxWidth/img.getWidth(null);
			height = img.getHeight(null) * scale;
		}else{
			height = maxHeight;
			scale = 1.0*maxHeight/img.getHeight(null);
			width = 1.0*img.getWidth(null) * scale;
		}
		Image newimg = img.getScaledInstance((int)width, (int)height,  java.awt.Image.SCALE_SMOOTH);  
		picture = new ImageIcon(newimg);
	}

	

	

}

